home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / multiclr.lha / MC / mc_spots.c < prev    next >
C/C++ Source or Header  |  1995-10-02  |  7KB  |  293 lines

  1. /******************************************************************************
  2. **                                                                           **
  3. ** MultiColor-Demo-Spots                                                     **
  4. **                                                                           **
  5. **---------------------------------------------------------------------------**
  6. ** V2.0 vom 02.10.95                                                         **
  7. ******************************************************************************/
  8.  
  9. #include "sc:source/mc/multicolor.h"
  10.  
  11. /* Protos */
  12.  
  13. void OpenAll(void);
  14. void CloseAll(void);
  15. void Spots(void);
  16. void ReadSpots(char *name);
  17. void DrawSpot(UBYTE i);
  18. double Intensity(double dist);
  19. UBYTE GetSign(UWORD x,UWORD y,UBYTE typ);
  20. void SetSign(UWORD x,UWORD y,UBYTE typ,double color);
  21. void Usage(void);
  22.  
  23. /* Global */
  24.  
  25. struct
  26. {
  27.     UWORD    x,y;
  28.     MCPoint    color;
  29.     UWORD    radiusx,radiusy;
  30. } SpotList[50];
  31.  
  32. UBYTE spotanz;
  33.  
  34. /* defines */
  35.  
  36. extern struct ExecBase         *SysBase;
  37. struct IntuitionBase        *IntuitionBase=0l;
  38. struct GfxBase                 *GfxBase=0l;
  39. struct Screen                *scr=0l;
  40. struct Window                *win=0l;
  41. MCHandle                    *mch=0l;
  42.  
  43. struct TagItem scrtags[]={
  44.     SA_Left,        0,
  45.     SA_Top,            0,
  46.     SA_Width,        0,
  47.     SA_Height,        0,
  48.     SA_Depth,        0,
  49.     SA_Colors,        0l,
  50.     SA_Type,        CUSTOMSCREEN,
  51.     SA_DisplayID,    PAL_MONITOR_ID,
  52.     TAG_DONE
  53. };
  54.  
  55. struct TagItem wintags[]={
  56.     WA_Left,        0,
  57.     WA_Top,            0,
  58.     WA_Width,        0,
  59.     WA_Height,        0,
  60.     WA_IDCMP,        IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY,
  61.     WA_Flags,        WFLG_SMART_REFRESH|WFLG_RMBTRAP|WFLG_BORDERLESS|WFLG_ACTIVATE,
  62.     WA_CustomScreen,0l,
  63.     TAG_DONE
  64. };
  65.  
  66. /* Funktions */
  67.  
  68. void OpenAll(void)
  69. {
  70. //    if(!(IntuitionBase=OpenLibrary("intuition.library",37))) CloseAll();
  71.     if(!(IntuitionBase=OpenLibrary("intuition.library",39))) CloseAll();
  72.     if(!(GfxBase=OpenLibrary("graphics.library",37))) CloseAll();
  73.  
  74.     if(!(scr=OpenScreenTagList(0l,scrtags))) CloseAll();
  75.     wintags[6].ti_Data=scr;
  76.  
  77.     if(!(win=OpenWindowTagList(0l,wintags))) CloseAll();
  78. }
  79.  
  80. void CloseAll(void)
  81. {
  82.     if(win)                CloseWindow(win);
  83.     if(scr)                CloseScreen(scr);
  84.     if(GfxBase)            CloseLibrary(GfxBase);
  85.     if(IntuitionBase)    CloseLibrary(IntuitionBase);
  86.     exit(0);
  87. }
  88.  
  89. void Spots(void)
  90. {
  91.     struct IntuiMessage *imsg;
  92.     ULONG iclass;
  93.     USHORT icode;
  94.     register UBYTE i=0,quit=0;
  95.     register UWORD x,y;
  96.     register LONG xp,yp;
  97.     double intens,dist,pi2=1.570796327;
  98.     MCPoint    akt;
  99.  
  100.     for(y=0;y<mch->yres;y++)
  101.     {
  102.         for(x=0;x<mch->xres;x++)
  103.         {
  104.             akt.r=akt.g=akt.b=0.0;
  105.             for(i=0;i<spotanz;i++)
  106.             {
  107.                 yp=y-SpotList[i].y;
  108.                 xp=x-SpotList[i].x;
  109.                 dist=sqrt((double)(xp*xp+yp*yp));
  110.                 if(dist<(SpotList[i].radiusx/5)) intens=1.0;
  111.                 else if(dist>(SpotList[i].radiusx*2.5)) intens=0.0;
  112.                 else
  113.                 {
  114.                     dist-=(SpotList[i].radiusx/5);
  115.                     dist=dist*pi2/((SpotList[i].radiusx*2.5));
  116.                     intens=(1.0-sin(dist));intens=intens*intens;
  117.                 }
  118.                 akt.r+=(intens*SpotList[i].color.r);
  119.                 akt.g+=(intens*SpotList[i].color.g);
  120.                 akt.b+=(intens*SpotList[i].color.b);
  121.             }
  122.             akt.r=fabs(akt.r);if(akt.r>1.0) akt.r=1.0;
  123.             akt.g=fabs(akt.g);if(akt.g>1.0) akt.g=1.0;
  124.             akt.b=fabs(akt.b);if(akt.b>1.0) akt.b=1.0;
  125.             MC_PutPixel(mch,x,y,akt);
  126.         }
  127.     }
  128.  
  129.     while(!quit)
  130.     {
  131.         WaitPort(win->UserPort);
  132.         while(imsg=GetMsg(win->UserPort))
  133.         {
  134.             iclass    =imsg->Class;
  135.             icode    =imsg->Code;
  136.             ReplyMsg(imsg);
  137.             switch(iclass)
  138.             {
  139.                 case IDCMP_RAWKEY:
  140.                     switch(icode)
  141.                     {
  142.                         case 0x45:        /* ESC */
  143.                         case 0x40:        /* Space */
  144.                             quit=1;break;
  145.                     }
  146.                     break;
  147.             }
  148.         }
  149.     }
  150. }
  151.  
  152. void ReadSpots(char *name)
  153. {
  154.     FILE *in;
  155.     register UBYTE i,j;
  156.     char spotline[80],mbuf[10];
  157.  
  158.     spotanz=0;
  159.     if(in=fopen(name,"rb"))
  160.     {
  161.         while(!feof(in))
  162.         {
  163.             j=0;
  164.             fgets(spotline,79,in);
  165.             for(i=0;i<3;i++) mbuf[i]=spotline[j+i];
  166.             mbuf[i]=0;j+=4;SpotList[spotanz].x=atoi(mbuf);
  167.             for(i=0;i<3;i++) mbuf[i]=spotline[j+i];
  168.             mbuf[i]=0;j+=4;SpotList[spotanz].y=atoi(mbuf);
  169.             for(i=0;i<7;i++) mbuf[i]=spotline[j+i];
  170.             mbuf[i]=0;j+=8;SpotList[spotanz].color.r=atof(mbuf);
  171.             for(i=0;i<7;i++) mbuf[i]=spotline[j+i];
  172.             mbuf[i]=0;j+=8;SpotList[spotanz].color.g=atof(mbuf);
  173.             for(i=0;i<7;i++) mbuf[i]=spotline[j+i];
  174.             mbuf[i]=0;j+=8;SpotList[spotanz].color.b=atof(mbuf);
  175.             for(i=0;i<3;i++) mbuf[i]=spotline[j+i];
  176.             mbuf[i]=0;j+=4;SpotList[spotanz].radiusx=atoi(mbuf);
  177.             for(i=0;i<3;i++) mbuf[i]=spotline[j+i];
  178.             mbuf[i]=0;j+=4;SpotList[spotanz].radiusy=atoi(mbuf);
  179.             spotanz++;
  180.         }
  181.         fclose(in);
  182.     }
  183. }
  184.  
  185. double Intensity(double dist)
  186. {
  187.     return(0.75+(0.25*cos(dist)*(2.0-cos(dist))));
  188. }
  189.  
  190.  
  191. void Usage(void)
  192. {
  193.     printf("Usage \n");
  194.     printf("\tmc_spots typ res name\n");
  195.     printf("\tres\typ | 0=ECS | 1=AGA,GFX-Card\n");
  196.     printf("\t--------+-------+---------------\n");
  197.     printf("\t e (ehb)| 64    | -             \n");
  198.     printf("\t l (low)| 32    | 256           \n");
  199.     printf("\t h (hi )| 16    | 256           \n");
  200.     printf("\t s (shi)| --    | 256           \n");
  201.     printf("\t--------+-------+---------------\n");
  202.     printf("\n\tname  spotliste\n");
  203. }
  204.  
  205. void main(int argc,char *argv[])
  206. {
  207.     UBYTE dep,typ,fail=0;
  208.     char res;
  209.  
  210.     if(argc==4)
  211.     {
  212.         typ=atoi(argv[1])&1;
  213.         res=argv[2][0];
  214.  
  215.         switch(typ)
  216.         {
  217.             case 0:        /* ECS */
  218.                 switch(res)
  219.                 {
  220.                     case 'E':
  221.                     case 'e':
  222.                         scrtags[4].ti_Data=dep=6;
  223.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  224.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  225.                         scrtags[7].ti_Data|=EXTRAHALFBRITELACE_KEY;
  226.                         break;
  227.                     case 'L':
  228.                     case 'l':
  229.                         scrtags[4].ti_Data=dep=5;
  230.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  231.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  232.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  233.                         break;
  234.                     case 'H':
  235.                     case 'h':
  236.                         scrtags[4].ti_Data=dep=4;
  237.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  238.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  239.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  240.                         break;
  241.                     case 'S':
  242.                     case 's':
  243.                         fail=1;
  244.                         break;
  245.                 }
  246.                 break;
  247.             case 1:        /* AGA,GFX-Card */
  248.                 switch(res)
  249.                 {
  250.                     case 'E':
  251.                     case 'e':
  252.                         fail=1;
  253.                         break;
  254.                     case 'L':
  255.                     case 'l':
  256.                         scrtags[4].ti_Data=dep=8;
  257.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  258.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  259.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  260.                         break;
  261.                     case 'H':
  262.                     case 'h':
  263.                         scrtags[4].ti_Data=dep=8;
  264.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  265.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  266.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  267.                         break;
  268.                     case 'S':
  269.                     case 's':
  270.                         scrtags[4].ti_Data=dep=8;
  271.                         wintags[2].ti_Data=scrtags[2].ti_Data=1416;        /* 944 */
  272.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  273.                         scrtags[7].ti_Data|=SUPERLACE_KEY;
  274.                         break;
  275.                 }
  276.                 break;
  277.         }
  278.  
  279.         if(!fail)
  280.         {
  281.             OpenAll();
  282.             if(mch=MC_Init(scr,win,dep))
  283.             {
  284.                 ReadSpots(argv[3]);
  285.                 Spots();
  286.             }
  287.         }
  288.         else Usage();
  289.     }
  290.     else Usage();
  291.     CloseAll();
  292. }
  293.